package com.sumansoul.slidingdeletedemo;

import android.util.Log;
import android.view.View;
import android.widget.LinearLayout;
import android.widget.TextView;

import com.blankj.utilcode.util.ScreenUtils;
import com.chad.library.adapter.base.BaseQuickAdapter;
import com.chad.library.adapter.base.BaseViewHolder;

import java.util.List;

public class MyListAdapter extends BaseQuickAdapter<LoginBean, BaseViewHolder> {
    public MyListAdapter(int layoutResId, List<LoginBean> data) {
        super(layoutResId, data);
    }

    @Override
    protected void convert(BaseViewHolder helper, LoginBean item) {

        //TODO 这里需要重新计算 item - containerView的宽度，否则containerView会显示错误(重要)
        LinearLayout containerView = helper.getView(R.id.lay_container);
        final SlidingDeleteView slidingDeleteView = helper.getView(R.id.slidingview);
        TextView tv_key = helper.getView(R.id.tv_key);
        TextView tv_cancel = helper.getView(R.id.tv_cancel);
        TextView tv_delete = helper.getView(R.id.tv_delete);

        containerView.getLayoutParams().width = ScreenUtils.getScreenWidth();
        slidingDeleteView.setEnable(true);
        //默认隐藏
        slidingDeleteView.setDeleteViewGone();

        tv_key.setText(item.getName());
        slidingDeleteView.setOnDeleteViewStateChangedListener(new SlidingDeleteView.OnDeleteViewStateChangedListener() {
            @Override
            public void onVisibile() {
                Log.d("LUO", "显示抽屉视图");
            }

            @Override
            public void onGone() {
                Log.d("LUO", "隐藏抽屉视图");
            }

            @Override
            public void onDownOrMove() {

            }
        });


        //添加点击事件
        helper.addOnClickListener(R.id.tv_key);
        helper.addOnClickListener(R.id.tv_cancel);
        helper.addOnClickListener(R.id.tv_delete);

    }
}
